package com.example.demo1.action;

import com.example.demo1.model.Flight;
import com.example.demo1.model.User;
import com.example.demo1.service.FlightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/flight")
public class FlightAction {

    @Autowired
    FlightService flightService;

    //陈泽源10.17
    @RequestMapping("/getUserFlight")
    public String getUserFlight(Model model, HttpSession session){
        User user=(User)session.getAttribute("USER_SESSION");
        List<Flight> flightList = flightService.getUserFlight(user);
        model.addAttribute("flightList",flightList);
        return "/userFlight";
    }
    //杨德旭10.19
    @RequestMapping("/getFlightList")
    public String getFlightList(Model model){
        List<Flight> flightList = flightService.getFlightList();
        model.addAttribute("flightList",flightList);
        return "/userAddFlight";
    }
    //杨德旭10.19
    @RequestMapping("/getUserJourney")
    public String getUserJourney(Model model, HttpSession session){
        User user=(User)session.getAttribute("USER_SESSION");
        List<Flight> flightList = flightService.getUserFlight(user);
        model.addAttribute("flightList",flightList);
        return "/userJourney";
    }
    //王兆楠10.18
    @RequestMapping("/getAllFlight")
    public String getAllFlight(Model model){
        List<Flight> flightList = flightService.getFlightList();
        model.addAttribute("flightList",flightList);
        return "/allFlight";
    }

    @RequestMapping("/getTicket")
    public String getTicket(Model model){
        List<Flight> flightList = flightService.getFlightList();
        model.addAttribute("flightList",flightList);
        return "/userTicket";
    }



}
